var TagManager = new function() {
	//Adds a tag as a button to the bottom toolbar of the win
	//On click the tag will be removed					
	this.addTagItem = function(uri, xpath, tag,win){
		var tb = win.getBottomToolbar();
		tb.add({
			text : tag,
			listeners : {
				"click" : function(){					
					ReferenceManager.removeTag(uri,xpath,tag,function(success) {
						Ext.ComponentMgr.get('mydesktop').getModule('ref-win').reloadReferences(null);
					});
					tb.remove(this);
					tb.doLayout();
					
				}
			}
		});
		tb.doLayout();
		Ext.ComponentMgr.get('mydesktop').getModule('ref-win').reloadReferences(null);
	},

	//all toolbar items will be remove, except the textfield to add a new tag
	this.resetToolbar = function(uri, win){		
		var tb = win.getBottomToolbar();
		tb.removeAll();
		tb.add({
			text : 'Tags:'
		});
		tb.add({
				xtype : 'textfield',
				name : 'tag',
				emptyText : 'enter tag here',
				enableKeyEvents : true,
				listeners : {
					"keydown" : function(field,	event) {
						if (event.getKey() == 13) {
							// uri, xpath, tag,
							var tagString = field.getValue();
							field.reset();
							ReferenceManager.addTag(uri,"",tagString,win,function(success) {
									
							});				
						}
					}
				}
		});
		tb.doLayout();
		
	}
	
}